<?php

namespace BP\CompteBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use BP\CompteBundle\Form\OperationForm;
use BP\CompteBundle\Form\OperationType;
use BP\CompteBundle\Entity\Compte;
use BP\CompteBundle\Entity\Operation;
use BP\UtilisateurBundle\Entity\Utilisateur;

use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\Security\Core\Exception\AuthenticationException;


class DefaultController extends Controller
{
    
    /*
     * copier/coller de la fonction du FOSUser
     */
    public function indexAction()
    {
    	$request = $this->container->get('request');
        /* @var $request \Symfony\Component\HttpFoundation\Request */
        $session = $request->getSession();
        /* @var $session \Symfony\Component\HttpFoundation\Session */

        // get the error if any (works with forward and redirect -- see below)
        if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
            $error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
        } elseif (null !== $session && $session->has(SecurityContext::AUTHENTICATION_ERROR)) {
            $error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
            $session->remove(SecurityContext::AUTHENTICATION_ERROR);
        } else {
            $error = '';
        }

        if ($error) {
            // TODO: this is a potential security risk (see http://trac.symfony-project.org/ticket/9523)
            $error = $error->getMessage();
        }
        // last username entered by the user
        $lastUsername = (null === $session) ? '' : $session->get(SecurityContext::LAST_USERNAME);

		$vue = array('error' => $error, 'last_username' => $lastUsername);
        return $this->container->get('templating')->renderResponse('BPCompteBundle:Default:indexLayout.html.twig',$vue);
    }

    public function displayErrorAction($error)
    {
        $vue = array('error' => $error);
       return $this->container->get('templating')->renderResponse('BPCompteBundle:Default:displayError.html.twig',$vue);
    }
}

